/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package forumgui;

import TamirsGui.GuiMessage;
import TamirsGui.GuiMsg;
import javax.swing.JOptionPane;

/**
 *
 * @author Roy
 */
public class Reply extends javax.swing.JDialog {

    /**
     * Creates new form NewJDialog
     */
    public Reply(java.awt.Frame parent, boolean modal,GuiMessage msg) {
        super(parent, modal);
        initComponents();
        this.msgThatIreplyTo = msg;
        this.subject = null;
        this.body = null;
        this.send = false;
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        exitButton = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        contentField = new javax.swing.JTextArea();
        jScrollPane3 = new javax.swing.JScrollPane();
        subjectField = new javax.swing.JTextField();
        titleLabel = new javax.swing.JLabel();
        contentLabel = new javax.swing.JLabel();
        sendButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);

        exitButton.setText("exit");
        exitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitButtonActionPerformed(evt);
            }
        });

        contentField.setColumns(20);
        contentField.setRows(5);
        jScrollPane2.setViewportView(contentField);

        jScrollPane3.setViewportView(subjectField);

        titleLabel.setText("subject");

        contentLabel.setText("content");

        sendButton.setText("send");
        sendButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sendButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(titleLabel)
                    .addComponent(contentLabel))
                .addGap(25, 25, 25)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 293, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 293, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(sendButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(exitButton)))
                .addContainerGap(63, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(43, 43, 43)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(titleLabel)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(exitButton)
                            .addComponent(sendButton)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(contentLabel)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitButtonActionPerformed
       this.setVisible(false);
    }//GEN-LAST:event_exitButtonActionPerformed

    private void sendButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendButtonActionPerformed
        // TODO add your handling code here:
        String subject = this.subjectField.getText();
        String body = this.contentField.getText();
        if (subject.equals("") && body.equals("" ))
        {
            JOptionPane.showMessageDialog(this,  "you must enter subject or body","Error ",JOptionPane.ERROR_MESSAGE);
            return;
        }
        this.sendPostMsg(subject,body);
        this.setVisible(false);
    }//GEN-LAST:event_sendButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea contentField;
    private javax.swing.JLabel contentLabel;
    private javax.swing.JButton exitButton;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JButton sendButton;
    private javax.swing.JTextField subjectField;
    private javax.swing.JLabel titleLabel;
    // End of variables declaration//GEN-END:variables

    private GuiMessage msgThatIreplyTo;
    private String subject;
    private String body;
    private boolean send;
    
    private void sendPostMsg(String subject, String body) {
        
        this.send = true;
        this.body = body;
        this.subject = subject;
    }

    public String getBody() {
        return body;
    }

    public boolean isSend() {
        return send;
    }

    public String getSubject() {
        return subject;
    }
    
    public static void main(String [] args)
    {
//        Reply view = new Reply(null, true, new GuiMsg(null, "hello", "מה המצב", GuiMsg.MessageType.postMsg, false));
//        view.setVisible(true);
    }
   
    
    
    
}
